<template>
  <div :id="id" :class="className" :style="{width: width, height: height}" />
</template>

<script>
import echarts from 'echarts'

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    id: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '200px'
    },
    height: {
      type: String,
      default: '200px'
    }
  },
  data () {
    return {
      chart: null
    }
  },
  mounted () {
    this.initChart()
  },
  beforeDestroy () {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart () {
      const _self = this
      let _chart = _self.chart

      _chart = echarts.init(document.getElementById(_self.id))

      _chart.setOption({
        color: ['#2dfff5', '#ec574d', '#ffea00', '#1954e4', '#7bd21f'],
        series: [
          {
            name: '塔吊参数信息',
            type: 'pie',
            radius: ['50%', '75%'],
            selectedMode: false,
            // selectedOffset: 10,
            avoidLabelOverlap: false,
            // hoverAnimation: false,
            startAngle: 40,
            label: {
              normal: {
                show: false,
                position: 'center'
              },
              emphasis: {
                show: true,
                formatter: '{b}',
                textStyle: {
                  fontSize: 38,
                  fontWeight: 'bold',
                  color: '#d8eefe'
                }
              }
            },
            labelLine: {
              normal: {
                show: false
              }
            },
            data: [
              {
                value: 120,
                name: '01'
              },
              {
                value: 120,
                name: '02'
              },
              {
                value: 120,
                name: '03'
              },
              {
                value: 120,
                name: '04'
              },
              {
                value: 120,
                name: '05'
              }
            ]
          }
        ]
      })

      _self.$emit('func', _chart)
    }
  }
}
</script>
